import os
import cv2
import json
import base64
import requests
import numpy as np


server_url = "http://127.0.0.1:8080"
# server_url = "http://172.17.0.2:8080"


def test_post(image_path):
    data_json={}
    with open(image_path, 'rb') as jpg_file:
        byte_content = jpg_file.read()
    base64_bytes = base64.b64encode(byte_content)
    data_json["img"] = [base64_bytes.decode('utf-8')]
    data_json["index"] = [os.path.basename(image_path)]

    #requests data示例
    # data_json['img'] = data_json['img']
    data = json.dumps(data_json)
    
    ret = requests.post(server_url + "/tccapi", data=data)
    result = json.loads(ret.content)
    print(result)


if __name__ == '__main__':
    img_path = '/media/mor/Data/Data/tianchiOCR/images/Xeon1OCR_round2_train2_20210816/T1e3CEFDBdXXXXXXXX_%21%210-item_pic.jpg'
    test_post(img_path)
